package com.tianqu.tms.www.transfer.action;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.jbarcode.JBarcode;
import org.jbarcode.encode.Code39Encoder;
import org.jbarcode.encode.EAN13Encoder;
import org.jbarcode.paint.BaseLineTextPainter;
import org.jbarcode.paint.EAN13TextPainter;
import org.jbarcode.paint.WideRatioCodedPainter;
import org.jbarcode.paint.WidthCodedPainter;
import org.jbarcode.util.ImageUtil;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAjaxAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.security.TmsUserProfile;
import com.tianqu.tms.core.util.DateUtil;
import com.tianqu.tms.core.util.Registry;
import com.tianqu.tms.core.util.StringUtil;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.Car;
import com.tianqu.tms.entity.Codes;
import com.tianqu.tms.entity.Member;
import com.tianqu.tms.entity.TransMarketCode;
import com.tianqu.tms.entity.TransferAcceptedInfo;
import com.tianqu.tms.entity.TransferFinanceInfo;
import com.tianqu.tms.entity.TransferPersonalCarInfo;
import com.tianqu.tms.www.transfer.controller.SeniorSearchPrintAjaxController;

public class SeniorSearchPrintAjaxAction extends TmsAjaxAction {
	private Logger logger = Logger.getLogger(SeniorSearchPrintAjaxAction.class);
	@Override
	public void process(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws TmsException {
		logger.debug(this.getClass().getName() + "#execute was called.");
		String serial = request.getParameter("serial");
		String type = request.getParameter("type");
		
		SeniorSearchPrintAjaxController controller = new SeniorSearchPrintAjaxController();
		try {
			uc.setAttribute("serial", serial);
			uc.setAttribute("type", type);
			controller.execute(uc);
		} catch (Exception e) {
			logger.error(e);
		}

		TransferAcceptedInfo accept = new TransferAcceptedInfo();
		accept = accept.getAcceptInfoBySerial(serial,"");
		Car car = new Car();
		Codes code = Codes.getInstance();
		TransferPersonalCarInfo person = new TransferPersonalCarInfo();
		Member member = Member.getInstance();
		String carName="";
		String regDate="";
		String carType="";
		String assessPircedy="";
		String sysdate="";
		String legal = "";
		String phone ="";
		String memberName="";
		
		String transferType1 = "";
		String transferType2 = "";
		String transferType3 = "";
		String transferType4 = "";
		String transferType5 = "";

		String carUse1 = "";
		String carUse2 = "";
		String carUse3 = "";
		String carUse4 = "";
		String carUse5 = "";
		String carUse6 = "";
		String carUse7 = "";
		String carUse8 = "";
		String carUse9 = "";
		String carUse10 = "";
		String carUse11 = "";
		String carUse12 = "";
		String carUse13 = "";
		String carUse14 = "";
		String carUse15 = "";
		String carUse16 = "";
		String carUse17 = "";
		String carUse18 = "";
		String carUse19 = "";
		String cardType = "";
		String vendorCode = "";
		String modelCode = "";
		String lipVi = "";// 车牌号码/VIN码
		String newOwner = "";
		String oldOwner = "";
		String registerCardNo = "";
		
		String newCardNoId = "";
		String oldCardNoId = "";
		String maw = "";
		String miw = "";
		String marketName = "";
		String taxpayerNo = "";
		String address = "";
		String bank = "";
		String marketPhone = "";
		String taxNo = "";
		String realName = "";
		String price = String.valueOf(accept.getPrice());
		int pp = 0;
		if(price!=null && !"".equals(price))
		{
			pp = Integer.parseInt(StringUtil.removeDH(price));
			//开始对pp进行处理
			miw = pp +".00";
			maw = cleanZero(splitNum(roundString(String.valueOf(pp))))+"整";
		}
		TmsUserProfile profile = uc.getUserProfile();
		realName = profile.getRealName();//登录者姓名
		TransMarketCode market = new TransMarketCode();
		market = market.getTransMarketCodeInfo(accept.getTransMarket());
		if(market!=null)
		{
			marketName = market.getMarketName();
			taxpayerNo = market.getTaxpayerNo();
			address = market.getAddress();
			bank = market.getBank();
			marketPhone = market.getPhone();
		}
		if(accept.getOwnerType() == 1)
		{
			oldCardNoId = accept.getCarOwnerIdCardNo();//
		}else{
			oldCardNoId = accept.getOwnerOrgNo();
		}
		if(accept.getNewOwnerType() == 1)
		{
			newCardNoId = accept.getNewcarOwnerIdCardNo();
		}else{
			newCardNoId = accept.getNewOwnerOrgNo();
		}
		if (StringUtil.isNullOrBlank(accept.getLicensePlate())) {
			lipVi = accept.getVin();
			newOwner = accept.getCarOwner();
		} else {
			lipVi = accept.getLicensePlate();
			oldOwner = accept.getCarOwner();
		}
		int carUse = 1;
		if(accept.getMarketType() == 1)
		{
			//库存
			car = car.findCarBySerial(accept.getBasicCarId());
			carUse =car.getCarUse();
			carName = car.getCarName();
			regDate = car.getRegDate();
			carType = code.getItemValueByItemIdAndItemCode(Codes.VEHICLE_TYPE, car.getCarType());
			cardType = code.getItemValueByItemIdAndItemCode(Codes.PLATE_TYPE, car.getCardType());
			vendorCode = car.getVendorCode();
			modelCode = car.getModelCode();
			registerCardNo = car.getRegisterCardNo();
			assessPircedy = StringUtil.addDH(String.valueOf(accept.getPg_price()));
			sysdate = DateUtil.getCurrentTimeStr2();
			member = member.findMemberInfoByMemId(String.valueOf(car.getMemberId()));
			if(member!=null)
			{
				legal = member.getLegal();
				phone = member.getPhone();
				memberName = member.getRealName();
			}

			if(car.getCarUse() == 1)
			{
				carUse1 = "√";
			}	
			if(car.getCarUse() == 2)
			{
				carUse19 = "√";
			}	
			if(car.getCarUse() == 3)
			{
				carUse17 = "√";
			}	
			if(car.getCarUse() == 4)
			{
				carUse14 = "√";
			}	
			if(car.getCarUse() == 5)
			{
				carUse15 = "√";
			}	
			if(car.getCarUse() == 6)
			{
				carUse16 = "√";
			}	
			if(car.getCarUse() == 7)
			{
				carUse8 = "√";
			}	
			if(car.getCarUse() == 8)
			{
				carUse9 = "√";
			}	
			if(car.getCarUse() == 9)
			{
				carUse10 = "√";
			}	
			if(car.getCarUse() == 10)
			{
				carUse18 = "√";
			}	
			if(car.getCarUse() == 11)
			{
				carUse2 = "√";
			}	
			if(car.getCarUse() == 12)
			{
				carUse3 = "√";
			}	
			if(car.getCarUse() == 13)
			{
				carUse4 = "√";
			}	
			if(car.getCarUse() == 14)
			{
				carUse5 = "√";
			}	
			if(car.getCarUse() == 15)
			{
				carUse6 = "√";
			}	
			if(car.getCarUse() == 16)
			{
				carUse7 = "√";
			}	
			if(car.getCarUse() == 17)
			{
				carUse13 = "√";
			}	
			if(car.getCarUse() == 18)
			{
				carUse12 = "√";
			}	
			if(car.getCarUse() == 19)
			{
				carUse11 = "√";
			}
		}
		if(accept.getMarketType() == 2)
		{
			//非库存
			person = person.getPersonalCarInfoBySerial(accept.getBasicCarId());
			carUse =person.getCarUse();
			carName = person.getCarName();
			regDate = person.getRegDate();
			vendorCode = person.getVendorCode();
			modelCode = person.getModelCode();
			carType = code.getItemValueByItemIdAndItemCode(Codes.VEHICLE_TYPE, person.getCarType());
			cardType = code.getItemValueByItemIdAndItemCode(Codes.PLATE_TYPE, person.getCardType());
			assessPircedy = StringUtil.addDH(String.valueOf(accept.getPg_price()));
			sysdate = DateUtil.getCurrentTimeStr2();
			registerCardNo = person.getRegisterCardNo();
			if(person.getCarUse() == 1)
			{
				carUse1 = "√";
			}	
			if(person.getCarUse() == 2)
			{
				carUse19 = "√";
			}	
			if(person.getCarUse() == 3)
			{
				carUse17 = "√";
			}	
			if(person.getCarUse() == 4)
			{
				carUse14 = "√";
			}	
			if(person.getCarUse() == 5)
			{
				carUse15 = "√";
			}	
			if(person.getCarUse() == 6)
			{
				carUse16 = "√";
			}	
			if(person.getCarUse() == 7)
			{
				carUse8 = "√";
			}	
			if(person.getCarUse() == 8)
			{
				carUse9 = "√";
			}	
			if(person.getCarUse() == 9)
			{
				carUse10 = "√";
			}	
			if(person.getCarUse() == 10)
			{
				carUse18 = "√";
			}	
			if(person.getCarUse() == 11)
			{
				carUse2 = "√";
			}	
			if(person.getCarUse() == 12)
			{
				carUse3 = "√";
			}	
			if(person.getCarUse() == 13)
			{
				carUse4 = "√";
			}	
			if(person.getCarUse() == 14)
			{
				carUse5 = "√";
			}	
			if(person.getCarUse() == 15)
			{
				carUse6 = "√";
			}	
			if(person.getCarUse() == 16)
			{
				carUse7 = "√";
			}	
			if(person.getCarUse() == 17)
			{
				carUse13 = "√";
			}	
			if(person.getCarUse() == 18)
			{
				carUse12 = "√";
			}	
			if(person.getCarUse() == 19)
			{
				carUse11 = "√";
			}
		}
		StringBuffer str = new StringBuffer();
		str.append("");
		if("1".equals(type))
		{
			//添加表打印次数  认证单
			str.append("<div style='WIDTH: 210mm; HEIGHT: 297mm' id='page1' class=jp-page><img src='style/images/memuB.jpg' style='WIDTH: 766px; HEIGHT: 1083px' class='jp-paper-background'/>" +
						"<div class='jp-label jp-comp-140'>" +
						""+serial+"</div>" +
						"<div class='jp-label jp-comp-141'>" +
						""+accept.getCarOwner()+"</div>" +
						"<div class='jp-label jp-comp-142'>" +
						""+accept.getLicensePlate()+"</div>" +
						"<div class='jp-label jp-comp-143'>" +
						""+vendorCode+""+modelCode+"</div>" +
						"<div class='jp-label jp-comp-144'>" +
						""+accept.getVin()+"</div>" +
						"<div class='jp-label jp-comp-145'>车况较好</div>" +
						"<div class='jp-label jp-comp-146'>" +
						""+regDate+"</div>" +
						"<div class='jp-label jp-comp-147'>" +
						""+carType+"</div>" +
						"<div class='jp-label jp-comp-148'>" +
						""+assessPircedy+"</div>" +
						"<div class='jp-label jp-comp-149'>" +
						""+sysdate+"</div>" +
//						"<div class='jp-label jp-comp-232'>（补"+(accept.getPg_printNum()-1)+"）</div>" +
						"</div>"
						);
			
		}
		if("2".equals(type))
		{
			//打印待办单
			String dbrq = DateUtil.getDateByTimeStamp(accept.getAgentTime());
			String jzrq = DateUtil.getAfterMonth1(2, dbrq);
			str.append("<div style='WIDTH: 210mm; HEIGHT: 297mm' id='page1' class=jp-page><img src='style/images/memuA.jpg' style='WIDTH: 766px; HEIGHT: 1083px'/>" +
						"<div class='jp-label jp-comp-150' style='margin-top:-4px;'>" +
						""+serial+"</div>" +
						"<div class='jp-label jp-comp-151' style=' margin-top:-2px;'>" +
						""+DateUtil.getTimeByTimeStamp(accept.getAgentTime())+"</div>" +
						"<div class='jp-label jp-comp-152' style=' margin-top:-4px;'>" +
						""+jzrq+"</div>" +
						"<div class='jp-label jp-comp-153' style=' margin-top:-10px; margin-left:-8px;'>" +
						""+legal+"</div>" +
						"<div class='jp-label jp-comp-154' style=' margin-top:-10px; margin-left:-8px;'>" +
						""+accept.getCarOwner()+"</div>" +
						"<div class='jp-label jp-comp-155' style=' margin-top:-10px;'>" +
						""+accept.getLicensePlate()+"</div>" +
						"<div class='jp-label jp-comp-156' style=' margin-top:-10px; margin-left:-20px;'>" +
						""+phone+"</div>" +
						"<div class='jp-label jp-comp-157'  style=' margin-top:-10px; margin-left:-20px;'>" +
						""+accept.getOwnerPhone()+"</div>" +
						"<div class='jp-label jp-comp-158' style=' margin-top:-10px;'>" +
						""+accept.getVin()+"</div>" +
						"<div class='jp-label jp-comp-159'>" +
						""+memberName+"</div>" +
//						"<div class='jp-label jp-comp-160' style=' margin-top:-22px; text-align:left;'>蔡明霞</div>" +
						"<div class='jp-label jp-comp-161'  style=' margin-top:-30px; '>" +
						""+DateUtil.getTimeByTimeStamp(accept.getAgentTime())+"</div>" +
						"<div class='jp-label jp-comp-162' style=' margin-top:-30px; '>" +
						""+jzrq+"</div>" +
						"<div class='jp-label jp-comp-163' style=' margin-top:-30px; '>" +
						""+serial+"</div>" +
						"<div class='jp-label jp-comp-164' style=' margin-top:-30px; '>" +
						""+accept.getLicensePlate()+"</div>" +
						"<div class='jp-label jp-comp-165' style='margin-top:-34px; '>" +
						""+serial+"</div>" +
						"<div class='jp-label jp-comp-166' style=' margin-top:-36px; '>" +
						""+accept.getLicensePlate()+"</div>" +
						"<div class='jp-label jp-comp-167' style=' margin-top:-30px; '>" +
						""+memberName+"</div>" +
						"<div class='jp-label jp-comp-168' style=' margin-top:-34px; '>" +
						""+DateUtil.getTimeByTimeStamp(accept.getAgentTime())+"</div>" +
//						"<div class='jp-label jp-comp-233'>（补"+(accept.getDb_printNum()-1)+"）</div>" +
						"</div>"
						);			
		}		
		if("3".equals(type))
		{
			if(accept.getTransferType() == 1)
			{
				transferType1 = "√";
			}
			if(accept.getTransferType() == 2)
			{
				transferType2 = "√";
			}
			if(accept.getTransferType() == 3)
			{
				transferType3 = "√";
			}
			if(accept.getTransferType() == 4)
			{
				transferType4 = "√";
			}
			if(accept.getTransferType() == 5)
			{
				transferType5 = "√";
			}
			//打印转移表
			String newAgentName = "";
			String newAgentPhone = "";
			if(accept.getNewAgentName() != null)
			{
				newAgentName = accept.getNewAgentName();
			}
			if(accept.getNewAgentPhone() != null)
			{
				newAgentPhone = accept.getNewAgentPhone();
			}
			str.append("<div style='WIDTH: 210mm; HEIGHT: 297mm' id='page1' class=jp-page><img src='style/images/menuE.jpg' style='WIDTH: 766px; HEIGHT: 1083px'/>" +
						"<div class='jp-label jp-comp-170' style=' margin-top:-10px; margin-left:-8px;'>" +
						""+accept.getNewcarOwner()+"</div>" +
						"<div class='jp-label jp-comp-171' style=' margin-top:-10px; margin-left:-8px;'>" +
						""+accept.getNewOwnerAddress()+"</div>" +
						"<div class='jp-label jp-comp-172' style=' margin-top:-10px;'>" +
						""+accept.getNewOwnerPhone()+"</div>" +
						"<div class='jp-label jp-comp-173' style=' margin-top:-10px; margin-left:-20px;'>" +
						""+accept.getNewOwnerZipCode()+"</div>" +
						"<div class='jp-label jp-comp-174' style=' margin-top:-10px;'>" +
						""+accept.getNewOwnerTelPhone()+"</div>" +
						"<div class='jp-label jp-comp-175' style=' margin-top:-10px;'>" +
						""+newAgentName+"</div>" +
						"<div class='jp-label jp-comp-176' style=' margin-top:-10px;'>" +
						""+newAgentPhone+"</div>" +
						"<div class='jp-label jp-comp-177' style=' margin-top:-22px; text-align:left;'>" +
						""+transferType1+"</div>" +
						"<div class='jp-label jp-comp-178' style=' margin-top:-22px; text-align:left;'>" +
						""+transferType2+"</div>" +
						"<div class='jp-label jp-comp-179' style=' margin-top:-22px; text-align:left;'>" +
						""+transferType3+"</div>" +
						"<div class='jp-label jp-comp-180' style=' margin-top:-22px; text-align:left;'>" +
						""+transferType4+"</div>" +
						"<div class='jp-label jp-comp-181' style=' margin-top:-22px; text-align:left;'>" +
						""+transferType5+"</div>" +
						"<div class='jp-label jp-comp-182' style=' margin-top:-22px; text-align:left;'>" +
						""+accept.getMoveOutProvince()+"</div>" +
						"<div class='jp-label jp-comp-183' style=' margin-top:-22px; text-align:left;'>" +
						""+accept.getMoveOutCity()+"</div>" +
						"<div class='jp-label jp-comp-184' style=' margin-top:-22px; text-align:left;'>" +
						""+cardType+"</div>" +
						"<div class='jp-label jp-comp-185' style=' margin-top:-22px; text-align:left;'>" +
						""+accept.getLicensePlate()+"</div>" +
						"<div class='jp-label jp-comp-186' style=' margin-top:-22px; text-align:left;'>" +
						""+vendorCode+modelCode+"</div>" +
						"<div class='jp-label jp-comp-187' style=' margin-top:-22px; text-align:left;'>" +
						""+accept.getVin()+"</div>" +
						"<div class='jp-label jp-comp-188' style=' margin-top:-22px; text-align:left;'>" +
						""+carUse1+"</div>" +
						"<div class='jp-label jp-comp-189' style=' margin-top:-22px; text-align:left;'>" +
						""+carUse2+"</div>" +
						"<div class='jp-label jp-comp-190' style=' margin-top:-22px; text-align:left;'>" +
						""+carUse3+"</div>" +
						"<div class='jp-label jp-comp-191' style=' margin-top:-22px; text-align:left;'>" +
						""+carUse4+"</div>" +
						"<div class='jp-label jp-comp-192' style=' margin-top:-22px; text-align:left;'>" +
						""+carUse5+"</div>" +
						"<div class='jp-label jp-comp-193' style=' margin-top:-22px; text-align:left;'>" +
						""+carUse6+"</div>" +
						"<div class='jp-label jp-comp-194' style=' margin-top:-22px; text-align:left;'>" +
						""+carUse7+"</div>" +
						"<div class='jp-label jp-comp-195' style=' margin-top:-22px; text-align:left;'>" +
						""+carUse8+"</div>" +
						"<div class='jp-label jp-comp-196' style=' margin-top:-22px; text-align:left;'>" +
						""+carUse9+"</div>" +
						"<div class='jp-label jp-comp-197' style=' margin-top:-22px; text-align:left;'>" +
						""+carUse10+"</div>" +
						"<div class='jp-label jp-comp-198' style=' margin-top:-22px; text-align:left;'>" +
						""+carUse11+"</div>" +
						"<div class='jp-label jp-comp-199' style=' margin-top:-22px; text-align:left;'>" +
						""+carUse12+"</div>" +
						"<div class='jp-label jp-comp-200' style=' margin-top:-22px; text-align:left;'>" +
						""+carUse13+"</div>" +
						"<div class='jp-label jp-comp-201' style=' margin-top:-22px; text-align:left;'>" +
						""+carUse14+"</div>" +
						"<div class='jp-label jp-comp-202' style=' margin-top:-22px; text-align:left;'>" +
						""+carUse15+"</div>" +
						"<div class='jp-label jp-comp-203' style=' margin-top:-22px; text-align:left;'>" +
						""+carUse16+"</div>" +
						"<div class='jp-label jp-comp-204' style=' margin-top:-22px; text-align:left;'>" +
						""+carUse17+"</div>" +
						"<div class='jp-label jp-comp-205' style=' margin-top:-22px; text-align:left;'>" +
						""+carUse18+"</div>" +
						"<div class='jp-label jp-comp-206' style=' margin-top:-22px; text-align:left;'>" +
						""+carUse19+"</div>" +
//						"<div class='jp-label jp-comp-234' style=' margin-top:-22px; text-align:left;'>（补"+(accept.getZy_printnum()-1)+"）</div>" +
						"</div>"
						);				
		}	
		if("4".equals(type))
		{
			TransferFinanceInfo finance=new TransferFinanceInfo();
			finance=finance.findFinanceInfoByserial(serial);//财务表
			
			String url = request.getRequestURL().toString();
			String uri = request.getRequestURI();
			url = url.replace(uri, "");// + contextPath;
			str.append("<img class='jp-paper-background' src='style/images/memuD.jpg' style='WIDTH:740px; HEIGHT:959px' />");
			str.append(""
					+ "<div class='jp-label jp-comp-41'>" + lipVi +"</div>"
					+ "<div class='jp-label jp-comp-42'>" + serial + "</div>"
					+ "<div class='jp-label jp-comp-43'>" + oldOwner + "</div>"
					+ "<div class='jp-label jp-comp-45'>" + serial + "</div>"
					+ "<div class='jp-label jp-comp-46'>" + accept.getLicensePlate() + "</div>"
					+ "<div class='jp-label jp-comp-47'>" + accept.getCarOwner() + "</div>"
					+ "<div class='jp-label jp-comp-48'>" + DateUtil.getCurrentTimeStr3() + "</div>"
					+ "<div class='jp-label jp-comp-61'>("+(accept.getLc_printNum()-1)+")</div>"
					+ "<div class='jp-label jp-comp-34'> <img  class='jp-image-view' src='"+url+accept.getPhoto_1()+"' style='WIDTH: 99mm; HEIGHT: 65mm'/> </div>"
					+ "<div class='jp-label jp-comp-35'> <img src='style/images/guohui.jpg' width='30mm' height='30mm'> </div>"
					+ "<div class='jp-label jp-comp-36'>大连市公安局交警支队车管所旧车交易市场机动车登记服务站</div>"
				  );
		}
		if("5".equals(type))
		{
			String carTypeName = carType;
			if(carUse==2||carUse==10)
			{
				carTypeName = code.getItemValueByItemIdAndItemCode(Codes.USER_NATURE, carUse);
			}
			//jiao yi piao
			str.append(""
					+ "<div style='WIDTH: 240mm; HEIGHT: 177mm' id=page1 class=jp-page>" 
					+ "<div class='jp-label jp-comp-207' style=' margin-top:-10px; margin-left:-8px;'>" 
					+ ""+DateUtil.getCurrentTimeStr()+"</div>" 
					+"<div class='jp-label jp-comp-208' style=' margin-top:-10px; margin-left:-8px;'>" +
					""+accept.getNewcarOwner()+"</div>" +
					"<div class='jp-label jp-comp-209' style=' margin-top:-10px; margin-left:-8px;'>" +
					""+accept.getNewOwnerAddress()+"</div>" +
					"<div class='jp-label jp-comp-210' style=' margin-top:-10px; margin-left:-8px;'>" +
					""+newCardNoId+"</div>" +
					"<div class='jp-label jp-comp-211' style=' margin-top:-10px; margin-left:-8px;'>" +
					""+accept.getNewOwnerPhone()+"</div>" +
					"<div class='jp-label jp-comp-212' style=' margin-top:-10px; margin-left:-8px;'>" +
					""+accept.getCarOwner()+"</div>" +
					"<div class='jp-label jp-comp-213' style=' margin-top:-10px; margin-left:-8px;'>" +
					""+oldCardNoId+"</div>" +
					"<div class='jp-label jp-comp-214' style=' margin-top:-10px; margin-left:-8px;'>" +
					""+accept.getOwnerAddress()+"</div>" +
					"<div class='jp-label jp-comp-215' style=' margin-top:-10px; margin-left:-8px;'>" +
					""+accept.getOwnerPhone()+"</div>" +
					"<div class='jp-label jp-comp-216' style=' margin-top:-10px; margin-left:-8px;'>" +
					""+accept.getLicensePlate()+"</div>" +
					"<div class='jp-label jp-comp-217' style=' margin-top:-10px; margin-left:-8px;'>" +
					""+registerCardNo+"</div>" +
					"<div class='jp-label jp-comp-218' style=' margin-top:-10px; margin-left:-8px;'>" +
					""+carTypeName+"</div>" +
					"<div class='jp-label jp-comp-219' style=' margin-top:-10px; margin-left:-8px;'>" +
					""+accept.getVin()+"</div>" +
					"<div class='jp-label jp-comp-220' style=' margin-top:-10px; margin-left:-8px;'>" +
					""+vendorCode+""+modelCode+"</div>" +
					"<div class='jp-label jp-comp-221' style=' margin-top:-10px; margin-left:-8px;'>" +
					""+accept.getCarMarketIn()+"</div>" +
					"<div class='jp-label jp-comp-222' style=' margin-top:-10px; margin-left:-8px;'>" +
					""+maw+"</div>" +
					"<div class='jp-label jp-comp-223' style=' margin-top:-10px; margin-left:-8px;'>" +
					""+miw+"</div>" +
					"<div class='jp-label jp-comp-224' style=' margin-top:-10px; margin-left:-8px;'>" +
					""+marketName+"</div>" +
					"<div class='jp-label jp-comp-225' style=' margin-top:-10px; margin-left:-8px;'>" +
					""+taxpayerNo+"</div>" +
					"<div class='jp-label jp-comp-226' style=' margin-top:-10px; margin-left:-8px;'>" +
					""+address+"</div>" +
					"<div class='jp-label jp-comp-227' style=' margin-top:-10px; margin-left:-8px;'>" +
					""+bank+"</div>" +
					"<div class='jp-label jp-comp-228' style=' margin-top:-10px; margin-left:-8px;'>" +
					""+marketPhone+"</div>" +
					"<div class='jp-label jp-comp-229' style=' margin-top:-10px; margin-left:-8px;'>增值税证号:</div>" +
					"<div class='jp-label jp-comp-230' style=' margin-top:-10px; margin-left:-8px;'>" +
					""+accept.getTaxNo()+"</div>" +
					"<div class='jp-label jp-comp-231' style=' margin-top:-10px; margin-left:-8px;'>" +
					""+realName+"</div></div>");
//			" +
//			"<div class='jp-label jp-comp-236'>（补"+accept.getGh_printnum()+"）</div>
		}
		if("6".equals(type))
		{
			//查验
			String lvin = "";
			String registration = "";
			String transferRegister = "";
			String changesVacate = "";
			String vinNum = "√";
			String engineNum = "——";
			String brandModel = "——";
			String drivingRecord = "——";
			String plateOrTireExterior = "——";
			String tireIntact = "——";
			String seatBelt = "——";
			String numberAxes = "——";
			String tireSize = "——";
			String lateralPortionOf = "——";
			String reflectiveMark = "——";
			String fireExtinguisher = "——";
			String security = "——";
			String externalMarking = "——";
			String siren = "——";
			String securityTechnology = "——";

			if (accept.getRegistration() == 1) {// 注册登记
				registration = "√";
			}
			if (accept.getTransferRegister() == 1) {// 转移登记
				transferRegister = "√";
			}
			if (accept.getChangesVacate() == 1) {// 变更迁出
				changesVacate = "√";
			}
			if ("1".equals(accept.getVinNum())) {// 车辆识别代号-----------------------------
				vinNum = "√";
			}
			if (accept.getVinNum() == null|| "".equals(accept.getVinNum())) {
				vinNum = "";
			}
			if ("1".equals(accept.getEngineNum())) {// 发动机型号/代码
				engineNum = "√";
			}
			if (accept.getEngineNum() == null|| "".equals(accept.getEngineNum())) {
				engineNum = "";
			}
			if ("1".equals(accept.getBrandModel())) {// 车辆品牌/型号
				brandModel = "√";
			}
			if (accept.getBrandModel() == null|| "".equals(accept.getBrandModel())) {
				brandModel = "";
			}
			if ("1".equals(accept.getPlateOrTireExterior())) {// 号牌/车辆外观形状
				plateOrTireExterior = "√";
			}
			if (accept.getPlateOrTireExterior() == null|| "".equals(accept.getPlateOrTireExterior())) {
				plateOrTireExterior = "";
			}
			if ("1".equals(accept.getTireIntact())) {// 轮胎完好情况
				tireIntact = "√";
			}
			if (accept.getTireIntact() == null|| "".equals(accept.getTireIntact())) {
				tireIntact = "";
			}
			if ("1".equals(accept.getSeatBelt())) {// 安全带、三角警告牌
				seatBelt = "√";
			}
			if (accept.getSeatBelt() == null|| "".equals(accept.getSeatBelt())) {
				seatBelt = "";
			}
			if ("1".equals(accept.getNumberAxes())) {// 外廓尺寸、轴数
				numberAxes = "√";
			}
			if (accept.getNumberAxes() == null
					|| "".equals(accept.getNumberAxes())) {
				numberAxes = "";
			}
			if ("1".equals(accept.getTireSize())) {// 轮胎规格
				tireSize = "√";
			}
			if (accept.getTireSize() == null
					|| "".equals(accept.getTireSize())) {
				tireSize = "";
			}
			if ("1".equals(accept.getLateralPortionOf())) {// 侧后部防护装置
				lateralPortionOf = "√";
			}
			if (accept.getLateralPortionOf() == null
					|| "".equals(accept.getLateralPortionOf())) {
				lateralPortionOf = "";
			}
			if ("1".equals(accept.getReflectiveMark())) {// 车身反光标示
				reflectiveMark = "√";
			}
			if (accept.getReflectiveMark() == null
					|| "".equals(accept.getReflectiveMark())) {
				reflectiveMark = "";
			}
			if ("1".equals(accept.getFireExtinguisher())) {// 灭火器
				fireExtinguisher = "√";
			}
			if (accept.getFireExtinguisher() == null
					|| "".equals(accept.getFireExtinguisher())) {
				fireExtinguisher = "";
			}
			if ("1".equals(accept.getDrivingRecord())) {// 行驶记录装置
				drivingRecord = "√";
			}
			if (accept.getDrivingRecord() == null
					|| "".equals(accept.getDrivingRecord())) {
				drivingRecord = "";
			}
			if ("1".equals(accept.getSecurity())) {// 安全出口、安全锤
				security = "√";
			}
			if (accept.getSecurity() == null
					|| "".equals(accept.getSecurity())) {
				security = "";
			}
			if ("1".equals(accept.getExternalMarking())) {// 外部标示、文字
				externalMarking = "√";
			}
			if (accept.getExternalMarking() == null
					|| "".equals(accept.getExternalMarking())) {
				externalMarking = "";
			}
			if ("1".equals(accept.getSiren())) {// 标志灯具、警报器
				siren = "√";
			}
			if (accept.getSiren() == null
					|| "".equals(accept.getSiren())) {
				siren = "";
			}
			if ("1".equals(accept.getSecurityTechnology())) {// 安全技术检验合格证明
				securityTechnology = "√";
			}
			if (accept.getSecurityTechnology() == null
					|| "".equals(accept.getSecurityTechnology())) {
				securityTechnology = "";
			}
			String strVin = "";
			if (StringUtil.isNullOrBlank(accept.getLicensePlate())) {
				lvin = accept.getVin();
				strVin = "<div class='jp-label jp-comp-13'>";
			} else {
				lvin = accept.getLicensePlate();
				strVin = "<div class='jp-label jp-comp-28'>";
			}
			String color = accept.getCy_color();
			if (color == null || "".equals(color)) {
				color = "";
			}
			String cy_passenger = accept.getCy_passenger();
			if (cy_passenger == null || "".equals(cy_passenger)) {
				cy_passenger = "";
			}
			String cy_carType = accept.getCy_carType();
			if (cy_carType == null || "".equals(cy_carType)) {
				cy_carType = "";
			}
			String checkConclusion = accept.getCheckConclusion();
			if (checkConclusion == null || "".equals(checkConclusion)) {
				checkConclusion = "";
			}
			String swp = "";
			if(accept.getCy_cardType()!=null && !"".equals(accept.getCy_cardType()))
			{
				swp = code.getItemValueByItemIdAndItemCode(Codes.PLATE_TYPE,Integer.parseInt(accept.getCy_cardType()));
			}
			str.append("<div style='WIDTH: 210mm; HEIGHT: 297mm' id='page1' class=jp-page>"
					+ "<img class='jp-paper-background' src='style/images/memuC.jpg' style='WIDTH: 766px; HEIGHT: 1083px'/>"
					+ "<div class='jp-label jp-comp-1'>"
					+ registration
					+ "</div>"
					+ "<div class='jp-label jp-comp-2'>"
					+ transferRegister
					+ "</div>"
					+ "<div class='jp-label jp-comp-3'>"
					+ changesVacate
					+ "</div>"
					+ "<div class='jp-label jp-comp-4'>"
					+ vinNum
					+ "</div>"
					+ "<div class='jp-label jp-comp-5'>"
					+ engineNum
					+ "</div>"
					+ "<div class='jp-label jp-comp-6'>"
					+ brandModel
					+ "</div>"
					+ "<div class='jp-label jp-comp-7'>"
					+ drivingRecord
					+ "</div>"
					+ "<div class='jp-label jp-comp-8'>"
					+ color
					+ "</div>"
					+ "<div class='jp-label jp-comp-9'>"
					+ cy_passenger
					+ "</div>"
					+ "<div class='jp-label jp-comp-10'>"
					+ cy_carType
					+ "</div>"
					+ "<div class='jp-label jp-comp-11'>"
					+ plateOrTireExterior
					+ "</div>"
					+ "<div class='jp-label jp-comp-12'>"
					+ checkConclusion
					+ "</div>"
					+ strVin
					+ lvin
					+ "</div>"
					+ "<div class='jp-label jp-comp-14'>"
					+ serial
					+ "</div>"
					+ "<div class='jp-label jp-comp-15'>"
					+ swp
					+ "</div>"
					+ "<div class='jp-image jp-comp-16'>"
					+ "<img class=jp-image-view src='"
					+ accept.getPhoto_1()
					+ "' style='WIDTH: 99mm; HEIGHT: 65mm'>"
					+ "</div>"
					+ "<div class='jp-label jp-comp-17'>"
					+ tireIntact
					+ "</div>"
					+ "<div class='jp-label jp-comp-18'>"
					+ seatBelt
					+ "</div>"
					+ "<div class='jp-label jp-comp-19'>"
					+ numberAxes
					+ "</div>"
					+ "<div class='jp-label jp-comp-20'>"
					+ tireSize
					+ "</div>"
					+ "<div class='jp-label jp-comp-21'>"
					+ lateralPortionOf
					+ "</div>"
					+ "<div class='jp-label jp-comp-22'>"
					+ reflectiveMark
					+ "</div>"
					+ "<div class='jp-label jp-comp-23'>"
					+ fireExtinguisher
					+ "</div>"
					+ "<div class='jp-label jp-comp-24'>"
					+ security
					+ "</div>"
					+ "<div class='jp-label jp-comp-25'>"
					+ externalMarking
					+ "</div>"
					+ "<div class='jp-label jp-comp-26'>"
					+ siren
					+ "</div>"
					+ "<div class='jp-label jp-comp-27'>"
					+ securityTechnology + "</div>" +
//					"<div class='jp-label jp-comp-237'>（补"+(accept.getCy_printNum()-1)+"）</div>" +
					"<div class='jp-label jp-comp-29'><img src='style/images/guohui.jpg' width='30mm' height='30mm'>" +
					"</div>" +
					"<div class='jp-label jp-comp-30'>大连市公安局交警支队车管所旧车交易市场机动车登记服务站" +
					"</div>" +
					"<div class='jp-label jp-comp-31'><img src='style/images/vin_before.png' width='95mm' height='19mm'>" +
					"</div>" +
					"<div class='jp-label jp-comp-32'><img src='style/images/vin_after.png' width='170mm' height='20mm'></div>");
		}

		String responseText = str.toString();

		responseValues(response, responseText, TEXT);
		logger.debug(this.getClass().getName() + "#execute was completed.");
	}
	private String splitNum(String s) {
		   if("".equals(s)) {
		    return "";
		   }
		   int index = s.indexOf(".");
		   String intOnly = s.substring(0, index);
		   String part1 = this.numFormat(1, intOnly);
		   String smallOnly = s.substring(index + 1);
		   String part2 = this.numFormat(2, smallOnly);
		   String newS = part1 + part2;
		   return newS;
		}

		private String roundString(String s) {
		   if("".equals(s)) {
		    return "";
		   }
		   double d = Double.parseDouble(s);
		   d = (d * 100 + 0.5) / 100;
		   s = new java.text.DecimalFormat("##0.000").format(d);
		   int index = s.indexOf(".");
		   String intOnly = s.substring(0, index);
		   if(intOnly.length() > 13) {
		    System.out.println("输入数据过大！（整数部分最多13位！）");
		    return "";
		   }
		   String smallOnly = s.substring(index + 1);
		   if(smallOnly.length() > 2) {
		    String roundSmall = smallOnly.substring(0, 2);
		    s = intOnly + "." + roundSmall;
		   }
		   return s;
		}
		public static String numFormat(int flag, String s) {
			   int sLength = s.length();
			   String bigLetter[] = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};
			   String unit[] = {"元", "拾", "佰", "仟", "万",
			     "拾", "佰", "仟",
			     "亿", "拾", "佰", "仟", "万"};
			   String small[] = {"分", "角"};
			   String newS = "";
			   for(int i = 0; i < sLength; i ++) {
			    if(flag == 1) {
			     newS = newS + bigLetter[s.charAt(i) - 48] + unit[sLength - i - 1];
			    } else if(flag == 2) {
			     newS = newS + bigLetter[s.charAt(i) - 48] + small[sLength - i - 1];
			    }
			   }
			   return newS;
			}
		private String cleanZero(String s) {
			   if("".equals(s)) {
			    return "";
			   }
			   while(s.charAt(0) == '零') {
			    s = s.substring(2);
			    if(s.length() == 0) {
			     return "零";
			    }
			   }
			   String regex1[] = {"零仟", "零佰", "零拾"};
			   String regex2[] = {"零亿", "零万", "零元"};
			   String regex3[] = {"亿", "万", "元"};
			   String regex4[] = {"零角", "零分"};
			   for(int i = 0; i < 3; i ++) {
			    s = s.replaceAll(regex1[i], "零");
			   }
			   for(int i = 0; i < 3; i ++) {
			    s = s.replaceAll("零零零", "零");
			    s = s.replaceAll("零零", "零");
			    s = s.replaceAll(regex2[i], regex3[i]);
			   }
			   for(int i = 0; i < 2; i ++) {
			    s = s.replaceAll(regex4[i], "");
			   }
			   s = s.replaceAll("亿万", "亿");
			   return s;
			}	
		
		private String createBarcode(HttpServletRequest request,String key){
			try {
				JBarcode localJBarcode = new JBarcode(EAN13Encoder.getInstance(), WidthCodedPainter.getInstance(), EAN13TextPainter.getInstance());
				localJBarcode.setEncoder(Code39Encoder.getInstance());
				localJBarcode.setPainter(WideRatioCodedPainter.getInstance());
				localJBarcode.setTextPainter(BaseLineTextPainter.getInstance());
				localJBarcode.setShowCheckDigit(false);
				String paramString = key + ".jpg";
				BufferedImage localBufferedImage = localJBarcode.createBarcode(key);
				String path = request.getSession().getServletContext().getRealPath("/").replace("/tmsweb", "") + Registry.getConfig(TmsConstants.WWW_UPLOAD_TIAO_UPLOAD_KEY);
				File file = new File(path);
				if (!file.exists()) file.mkdirs();
				FileOutputStream localFileOutputStream = new FileOutputStream(path + "/" + paramString);
				ImageUtil.encodeAndWrite(localBufferedImage, "jpeg", localFileOutputStream, 96, 96);
				localFileOutputStream.close();
				return Registry.getConfig(TmsConstants.WWW_UPLOAD_TIAO_UPLOAD_KEY) + "/" + paramString;
			} catch (Exception e) {
				logger.error("createBarcode error", e);
			}
			return "";
		}
		
}
